package br.org.bertol.mestrado.search;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import br.org.bertol.mestrado.Path;
import br.org.bertol.mestrado.Verify;

public class RandomSolution 
{
	private Verify verify;
	
	private List<Path> randomSolutions;
	
	public RandomSolution()
	{
	}
	
	public void setVerify(final Verify sa)
	{
		verify = sa;
	}
	
	public List<Path> generateRandomSolutions(final int max_random_solutions)
	{
		if(randomSolutions != null)
			return randomSolutions;
		
		randomSolutions = new ArrayList<Path>(max_random_solutions);
		
		for (int i = 0; i < max_random_solutions; i++)
		{
			final Path randomPath = new Path();
			
			randomPath.setRoute((ArrayList<Integer>)verify.getClasses().clone());
						
			while(randomPath.gethHeigtht() == Integer.MAX_VALUE)
			{
				Collections.shuffle(randomPath.getRoute());
				
				verify.verifyPrecedence(randomPath);
			}
			
			verify.verifyDependency(randomPath, true);
			
			randomSolutions.add(randomPath);
		}
		
		return randomSolutions;
	}
}
